home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************************
-
- PROJECT: clut_fade.π
-
- FILE: shell.c
-
- PURPOSE: 'clut' fading functions
-
- STATUS: Public Domain Demo.
-
- ********************************************************************************/
-
- //================================= INCLUDES ====================================
-
- #include "shell.h"
- #include "fade.h"
-
- //================================= FUNCTIONS ===================================
-
- void init_toolbox(void);
- void test_window(void);
-
-
- /*********************************** main ***************************************/
- extern
- void main(void)
- {
- init_toolbox();
- test_window();
- }
- /*** main ***/
-
- /********************************** init_toolbox ********************************/
- static
- void init_toolbox(void)
- {
- MaxApplZone();
- MoreMasters();
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- FlushEvents(everyEvent, 0);
- }
- /*** init_toolbox ***/
-
- /********************************** test_window *********************************/
- static
- void test_window(void)
- {
- DialogPtr d;
- GrafPtr g;
- short hit;
- GDHandle hGD;
- CTabHandle hCTab;
- long ticks;
-
- if (d = GetNewDialog(128, nil, (WindowPtr) -1L))
- {
- GetPort(&g);
- SetPort(d);
- ShowWindow(d);
-
- do
- {
- ModalDialog(nil, &hit);
- switch (hit)
- {
- // fade all monitors to black
- case 2:
- // fade out
- fade_to_black(128, fadeAll, true);
- // wait a few seconds
- Delay (120L, &ticks);
- // fade in
- fade_to_black(128, fadeAll, false);
- break;
-
- // fade main monitor to black
- case 3:
- // fade out
- fade_to_black(128, fadeMainOnly, true);
- // wait a few seconds
- Delay (120L, &ticks);
- // fade in
- fade_to_black(128, fadeMainOnly, false);
- break;
-
- // fade all monitors except main monitor to black
- case 4:
- // fade out
- fade_to_black(128, fadeAllButMain, true);
- // wait a few seconds
- Delay (120L, &ticks);
- // fade in
- fade_to_black(128, fadeAllButMain, false);
- break;
-
- // fade main monitor to red
- case 5:
- {
- CTabHandle origColors;
- GDHandle mainDevice = GetMainDevice();
- RGBColor aColor;
-
- // make a copy of the color table so we can restore it later
- copy_gdevice_clut(mainDevice,&origColors);
-
- // fade to a color
- aColor.red = 65535;
- aColor.green = 0;
- aColor.blue = 0;
- fade_to_color(128,&aColor,mainDevice);
-
- // wait a few seconds
- Delay (120L, &ticks);
-
- // fade back to original color table
- fade_to_clut(128,origColors,mainDevice);
-
- // dispose the copy we made
- DisposeHandle((Handle)origColors);
- }
- break;
-
- // fade main monitor through rainbow
- case 6:
- {
- CTabHandle origColors;
- CTabHandle newColors;
- short x;
- GDHandle mainDevice = GetMainDevice();
-
- // make a copy of the color table so we can restore it later
- copy_gdevice_clut(mainDevice,&origColors);
-
- for (x = 128; x < 135; x++)
- {
- // get a custom color table (red or blue)
- newColors = GetCTable(x);
- // limit it to current depth
- (**newColors).ctSize = (**origColors).ctSize;
- SetHandleSize((Handle)(**newColors).ctTable, sizeof(short) + (sizeof(RGBColor) * ((**newColors).ctSize+1)));
- // fade to the custow color table
- fade_to_clut(40,newColors,mainDevice);
- ReleaseResource((Handle)newColors);
- }
-
- // fade back to original color table
- fade_to_clut(40,origColors,mainDevice);
- // dispose the copy we made
- DisposeHandle((Handle)origColors);
- }
- break;
-
- // fade to inverted clut
- case 7:
- {
- CTabHandle origColors;
- CTabHandle newColors;
- RGBColor aColor;
- short x;
- GDHandle mainDevice = GetMainDevice();
-
- // make a copy of the color table so we can restore it later
- copy_gdevice_clut(mainDevice,&origColors);
- // make a copy of the color table so we manipulate it
- copy_gdevice_clut(mainDevice,&newColors);
- // reverse order of colors for a fun effect
- for (x = 0; x < (((**newColors).ctSize+1)/2); x++)
- {
- aColor = (**newColors).ctTable[x].rgb;
- (**newColors).ctTable[x].rgb = (**newColors).ctTable[(**newColors).ctSize - x].rgb;
- (**newColors).ctTable[(**newColors).ctSize - x].rgb = aColor;
- }
- // fade to it
- fade_to_clut(128,newColors,mainDevice);
- // wait a few seconds
- Delay (120L, &ticks);
- // fade back to original color table
- fade_to_clut(128,origColors,mainDevice);
- // dispose the copy we made
- DisposeHandle((Handle)origColors);
- }
- break;
- }
- }
- while (hit != OK);
-
- SetPort(g);
- DisposDialog(d);
- }
- }
- /*** test_window ***/
-
- //===================================== EOF =====================================